package com.cjm.algorithm.backtracking;

import java.util.*;
import java.util.stream.Collectors;

public class Ti491 {
    public static void main(String[] args) {
        Ti491 ti491 = new Ti491();
        List<List<Integer>> subsequences = ti491.findSubsequences(new int[]{4,6,7,7});
        System.err.println("OK");
    }

    List<List<Integer>> res = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();

    public List<List<Integer>> findSubsequences(int[] nums) {
        res.clear();
        path.clear();
        dup.clear();
        method491(nums, 0);
        return res;
    }

    Map<String, Integer> dup = new HashMap<>();
    private void method491(int[] nums, int startIndex) {
        if (path.size() >= 2) {
            res.add(new ArrayList<>(path));
        }
        Set<Integer> xx = new HashSet<>();
        for (int i = startIndex; i < nums.length; i++) {
            int num = nums[i];
            Integer last = path.peekLast();
            if (last != null && num < last) {
                continue;
            }
            if (xx.contains(num)) {
                continue;
            }

            path.addLast(num);
            xx.add(num);
            method491(nums, i + 1);
            path.removeLast();
        }
    }
}
